<?php

class Jd_hunter_total_month_model extends MY_Model {

    public function __construct()
    {
        $this->modelename='Jd_hunter_total_month_model';
        $this->tablename='hunter_total_month';
        parent::__construct();
    }



    /**
     * 检查插入或者更新数据
     */
    public function getupodatemoth($row){
        $date=date('Y-m-d');
        $month=date('Y-m-1');
        $user_id=$row['user_id'];
        $money=$row['money'];
        $row['addtime']=time();
        $sql="select 1 from jd_hunter_total_month where `date`='$month' AND  user_id=$user_id ";
        $result=$this->GetBySql($sql,0);
        if(empty($result)){
            $row['usemoney']=$money;
            unset( $row['money']);
            $row['finishnub']=1;
            $row['date']=$month;
            return  $this->add($this->tablename,$row);
        }else{
            $sql='update jd_hunter_total_month set  finishnub=finishnub+1 ,usemoney=usemoney+'.$money ." where `date`='$month' AND  user_id=$user_id ";
            return $this->db->query($sql);
        }

    }












}
